#include "common.h"
namespace common {
int longestConsecutive(std::vector<int> &nums) {
    std::unordered_set<int> s(nums.begin(), nums.end());
    int longest_num = 0;
    for (auto elem : nums) {
        int current_num = 0;
        int consecutive_nums = 0;
        if (!s.contains(elem - 1)) {
            consecutive_nums = 1;
            current_num = elem;
            while (s.contains(current_num + 1)) {
                consecutive_nums++;
                current_num = current_num + 1;
            }
            longest_num = std::max(consecutive_nums, longest_num);
        }
    }
    return longest_num;
}
} // namespace common
